import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:super_tool_server/business/config_manager.dart';
import 'package:super_tool_server/common/constant.dart';
import 'package:super_tool_server/common/utils/log.dart';
import 'package:super_tool_server/page/main/main_app_page.dart';

void main() {
  runZoned<Future<void>>(
    () async {
      WidgetsFlutterBinding.ensureInitialized();
      await Hive.initFlutter();
      await ConfigManager.getInstance().init();
      configLogger();
      runApp(MainAppUI());
    },
    // ignore: deprecated_member_use
    onError: (error, stackTrace) {
      // ignore: avoid_print
      print('dart_error: error: $error, stack: $stackTrace');
    },
  );

  FlutterError.onError = (FlutterErrorDetails details) {
    bool isDebug = false;
    assert(() {
      isDebug = true;
      return true;
    }());
    if (isDebug) {
      // print
      FlutterError.dumpErrorToConsole(details);
    } else {
      // In production mode report to the application zone to report
      Zone.current.handleUncaughtError(details.exception, details.stack!);
    }
  };
}
